from typing import Optional
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, BooleanField, SubmitField
from wtforms.validators import DataRequired, Email, EqualTo, Length
from wtforms import StringField, SelectField, validators
from wtforms.validators import Optional


class RegistrationForm(FlaskForm):
    # 用户名字段，使用StringField类型，验证器为DataRequired()和Length(min=3, max=64)
    username = StringField('用户名', validators=[DataRequired(), Length(min=3, max=64)])
    # 电子邮箱字段，使用StringField类型，验证器为DataRequired()和Email()
    email = StringField('电子邮箱', validators=[DataRequired(), Email()])
    # 添加Length验证器到手机号字段，验证器为DataRequired()和Length(min=11, max=11)
    phone = StringField('手机号码', validators=[
        DataRequired(), 
        Length(min=11, max=11, message='手机号必须是11位数字')
    ])
    # 密码字段，使用PasswordField类型，验证器为DataRequired()和Length(min=8)
    password = PasswordField('密码', validators=[DataRequired(), Length(min=8)])
    # 确认密码字段，使用PasswordField类型，验证器为DataRequired()和EqualTo('password')
    confirm_password = PasswordField('确认密码', validators=[DataRequired(), EqualTo('password')])
    # 提交按钮，使用SubmitField类型
    submit = SubmitField('注册')

class LoginForm(FlaskForm):
    username = StringField('用户名或邮箱', validators=[DataRequired()])  # 移除长度限制
    password = PasswordField('密码', validators=[DataRequired()])
    remember = BooleanField('记住我')
    submit = SubmitField('登录')


class SeatSelectionForm(FlaskForm):
    seats = StringField('Selected Seats', [validators.DataRequired()])
    payment_method = SelectField('Payment Method', choices=[
        ('微信支付', '微信支付'),
        ('支付宝', '支付宝'),
        ('银联', '银联')
    ], validators=[validators.DataRequired()])

class EditProfileForm(FlaskForm):
    username = StringField('用户名', validators=[DataRequired(), Length(min=3, max=64)])
    email = StringField('电子邮箱', validators=[DataRequired(), Email()])
    phone = StringField('手机号码', validators=[
        DataRequired(), 
        Length(min=11, max=11, message='手机号必须是11位数字')
    ])
    password = PasswordField('新密码', validators=[Optional(), Length(min=8)])
    confirm_password = PasswordField('确认新密码', validators=[
        EqualTo('password', message='两次密码不一致')
    ])
    submit = SubmitField('保存更改')